package com.mrjy.common.config.listener;

import javax.servlet.ServletContext;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.mrjy.common.config.WebSocket;
import com.mrjy.common.entity.AccessLog;
import com.mrjy.common.entity.UserInfo;
import com.mrjy.common.util.GlobalConstant;
import com.mrjy.maintain.bo.IAccessLogBo;

/**
 * Application Lifecycle Listener implementation class SessionAttriburteListener
 * 监听session属性
 */
@WebListener
public class SessionAttriburteListener implements HttpSessionAttributeListener {
	
	ApplicationContext ctx = null;
	
	IAccessLogBo accessLogBo = null;
	
    public SessionAttriburteListener() {
    }

	/**
     * @see HttpSessionAttributeListener#attributeRemoved(HttpSessionBindingEvent)
     */
    public void attributeRemoved(HttpSessionBindingEvent hse)  { 
//    	try {
//			ServletContext sc = hse.getSession().getServletContext();
//			this.ctx = WebApplicationContextUtils.getWebApplicationContext(sc);
//			accessLogBo = (IAccessLogBo) ctx.getBean("accessLogBo");
//			//监听USER_INFO的移除
//			UserInfo userInfo = (UserInfo) hse.getSession().getAttribute("user");
//			if (userInfo!=null) {
//				AccessLog accessLog = new AccessLog();
//				accessLog.setType("2");
//				accessLogBo.txInsert(accessLog, userInfo);
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
    }

	/**
     * @see HttpSessionAttributeListener#attributeAdded(HttpSessionBindingEvent)
     */
    public void attributeAdded(HttpSessionBindingEvent arg0)  { 
         // TODO Auto-generated method stub
    }

	/**
     * @see HttpSessionAttributeListener#attributeReplaced(HttpSessionBindingEvent)
     */
    public void attributeReplaced(HttpSessionBindingEvent arg0)  { 
         // TODO Auto-generated method stub
    }
	
}
